var app = getApp();
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    bigMask: false,
    reward:[1,2,3,4,5,6,7],
    consulList:[
      {
        "icon":'../../images/tsjyiocn.png',
        "title":'新冠肺炎',
        "tip":'辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
      {
        "icon": '../../images/tsjyiocn.png',
        "title": '新冠肺炎',
        "tip": '辟谣 防护知识'
      },
    ]
  },
  // 点击切换套餐选项卡
  taocan: function(e) {
    // console.log(e);
    var that = this;
    var zx_id = e.currentTarget.dataset.id
    app.util.request({
      'url': 'entry/wxapp/Zixun.zixunyi',
      data: {
        zx_id: zx_id
      },
      success: function(res) {
        that.setData({
          zixun: res.data,
          zx_id: zx_id
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
    that.setData({
      currentTab: e.currentTarget.dataset.index
    })

  },
  btdetail(e) {
    var id = e.currentTarget.dataset.id
    var p_id = e.currentTarget.dataset.p_id
    //增加阅读数
    app.util.request({
      'url': 'entry/wxapp/Zixun.addyuedu',
      data: {
        id: id,
      },
      success: function(res) {
        console.log(res)
      },
      fail: function(err) {
        console.log(err)
      },
    })
    app.util.request({
      'url': 'entry/wxapp/Zixun.erweima',
      data: {
        id: id,
        p_id:p_id
      },
      success: function(res) {
        console.log(res)
      },
      fail: function(err) {
        console.log(err)
      },
    })
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/zixunanlixq/zixunanlixq?id=' + id + '&p_id=' + p_id,
    })
  },
  taocan1: function(e) {
    console.log(e);
    var that = this;
    var zx_id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    console.log(index)
    app.util.request({
      'url': 'entry/wxapp/Zixun.zixunyi',
      data: {
        zx_id: zx_id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          zixun: res.data,
          currentTab: index
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  },
  searchbtn() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/search/search',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options,"------------------");
    var zx_id = options.zx_id
    var index = options.index
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    console.log(page)
    if (zx_id != undefined) {
      app.util.request({
        'url': "entry/wxapp/Index.zixunfenlei",
        success: function(res) {
          app.util.request({
            'url': 'entry/wxapp/Zixun.zixunyi',
            data: {
              zx_id: zx_id,
              page: page
            },
            success: function(res) {
              console.log(res,"111111")
              that.setData({
                zixun: res.data,
              })
            },
            fail: function(err) {
              console.log(err)
            },
          })
          that.setData({
            taocan: res.data,
          })
        },
        fail: function(err) {
          console.log(err)
        },
      })
    } else {
      app.util.request({
        'url': "entry/wxapp/Index.zixunfenlei",
        success: function(res) {
          console.log(res)
          var zx_id = res.data[0].zx_id
          app.util.request({
            'url': 'entry/wxapp/Zixun.zixunyi',
            data: {
              zx_id: zx_id,
              page: page
            },
            success: function(res) {
              console.log(res,"====================")
              that.setData({
                zixun: res.data,

              })
            },
            fail: function(err) {
              console.log(err)
            },
          })
          that.setData({
            taocan: res.data,
            zx_id: zx_id
          })
        },
        fail: function(err) {
          console.log(err)
        },
      })
    }
    that.setData({
      currentTab: index,
      bgc: bgc,
      zx_id: zx_id
    })
  },
  toast: function() {
    wx.redirectTo({
      url: '/hyb_yl/tabBar/index/index'
    })
  },
  toast1: function(e) {
    //console.log(e)
    wx.redirectTo({
      url: '/hyb_yl/tabBar/community/community'
    })
  },
  toast2: function() {
    wx.redirectTo({
      url: '/hyb_yl/mysubpages/pages/shop/shop'
    })
  },
  toast3: function() {
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Myphone',
      data: {
        openid: openid
      },
      success: function(res) {
        app.globalData.myphone = res.data.data
        app.globalData.openid = openid
      },
      fail: function(err) {
        console.log(err)
      },

    })
    setTimeout(function() {
      wx.redirectTo({
        url: '/hyb_yl/tabBar/my/my'
      })
    }, 350)
  },
  toast4() {
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Myphone',
      data: {
        openid: openid
      },
      success: function(res) {
        app.globalData.myphone = res.data.data
        app.globalData.openid = openid
      },
      fail: function(err) {
        console.log(err)
      },

    })
    wx.redirectTo({
      url: '/hyb_yl/userLife/pages/jibingyufang/jibingyufang'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    wx.hideNavigationBarLoading()
    var that = this
    var zx_id = that.data.zx_id
    var openid = wx.getStorageSync('openid')
    console.log(openid)
    if (openid) {
      that.setData({
        bigMask: true
      })
    } else {
      that.setData({
        bigMask: false
      })
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  //咨询
})